/*
 *  Copyright (C) 2010 Jonathan MERCIER <bioinfornatics@fedoraproject.org>,
 *  Louise-Amélie SCHMITT <louise-amelie.schmitt@etu.u-bordeaux1.fr>,
 *  Florence Maurier <florence_maurier@orange.fr>,
 *  Marianne Dussart <marianne.dussart@orange.fr>,
 *  Nicolas Fontaine <nifontaine@gmail.com>
 *
 *  JACoMode is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  JACoMode is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with JACoMode.  If not, see <http://www.gnu.org/licenses/>.
 */
package fr.ubdx1.jacomode.models;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 *
 * @author Jonathan MERCIER <bioinfornatics@fedoraproject.org>,Louise-Amélie SCHMITT <louise-amelie.schmitt@etu.u-bordeaux1.fr>,Florence Maurier <florence_maurier@orange.fr>,Marianne Dussart <marianne.dussart@orange.fr>,Nicolas Fontaine <nifontaine@gmail.com>
 */
public class Compare
{
    private ArrayList<String> totalClassArray;
    private ArrayList<String> sigmaArray;
    private ArrayList<String> epsilonArray;
    private ArrayList<String> totalEfmArray;
    private ArrayList<String> totalNoiseArray;

    public Compare(String path)
    {
        addComparaisonFile(path);
    }

    public Compare()
    {
        totalClassArray   = new ArrayList<String>();
        sigmaArray        = new ArrayList<String>();
        epsilonArray      = new ArrayList<String>();
        totalEfmArray     = new ArrayList<String>();
        totalNoiseArray   = new ArrayList<String>();
    }

    /**
     * Add a file to compare.
     * @param path file path
     */
    public void addComparaisonFile(String path)
    {
        String  totalefm;
        String  totalnoise;
        String  totalclass;
        String  sig;
        String  eps;
        Scanner s       = null ;
        String  mot1    = "total class, average efm by class, total efm, noise effective";
        String  mot2    = "sigma, epsilon";
        Pattern p1      = Pattern.compile(mot1);
        Pattern p2      = Pattern.compile(mot2);
        String  bl      = "";
        String  line    = "";
        String  line2   = "";
        int     position= 1;
        try
        {
            s = new Scanner(new BufferedReader(new FileReader(path)));
        }
        catch(IOException error)
        {
            error.printStackTrace();
        }
        finally
        {
            while (s.hasNextLine())
            {
                bl          = "";
                bl          = s.nextLine();
                Matcher m1  = p1.matcher(bl);
                boolean b1  = m1.matches();
                Matcher m2  = p2.matcher(bl);
                boolean b2  = m2.matches();
                if (b1)
                {
                    bl  = s.nextLine();
                    line= bl;
                }
                else if (b2)
                {
                    bl      = s.nextLine();
                    line2   = bl;
                }
            }
            if (s != null)
            {
                s.close();
            }
        }
        s   = null;
        s   = new Scanner(line);
        while (s.hasNext())
        {
            bl  = "";
            bl  = s.next();
            if (position ==1)
            {
                totalclass  = bl.substring(0,(bl.length()-1));
                totalClassArray.add(totalclass);
            }
            else if (position ==3)
            {
                totalefm    = bl.substring(0,(bl.length()-1));
                totalEfmArray.add(totalefm);
            }
            else if (position ==4)
            {
                totalnoise  = bl;
                totalNoiseArray.add(totalnoise);
            }
            position++;

        }
        if (s != null)
        {
            s.close();
        }
        position=1;
        s   = null;
        s   = new Scanner(line2);
        while (s.hasNext())
        {
            bl = "";
            bl = s.next();
            if (position ==1)
            {
                sig=bl.substring(0,(bl.length()-1));
                sigmaArray.add(sig);
            }
            else if (position ==2)
            {
                eps=bl;
                epsilonArray.add(eps);
            }
            position=position+1;

        }
        if (s != null)
        {
            s.close();
        }
    }

    /**
     * Returns an ArrayList containing all the classes.
     * @return an ArrayList containing all the classes
     */
    public ArrayList<String> getTotalclass()
    {
        return totalClassArray;
    }

    /**
     * Returns an ArrayList containing all the EFM.
     * @return an ArrayList containing all the EFM
     */
    public ArrayList<String> getTotalefm()
    {
        return totalEfmArray;
    }

    /**
     * Returns an ArrayList containing the EFM that don't appear in any class.
     * @return an ArrayList containing the EFM that don't appear in any class
     */
    public ArrayList<String> getTotalnoise()
    {
        return totalNoiseArray;
    }
        /**
     * Returns sigma.
     * @return sigma
     */
    public ArrayList<String> getSigma()
    {
        return sigmaArray;
    }

    /**
     * Returns epsilon.
     * @return epsilon
     */
    public ArrayList<String> getEpsilon()
    {
        return epsilonArray;
    }
}
